package main

import (
	"bufio"
	"fmt"
	"log"
	"math/rand"
	"os"
	"strconv"
	"strings"
	"time"
)

func main() {
	second := time.Now().Unix()
	rand.Seed(second)
	target := rand.Intn(100) + 1
	fmt.Println("请输入一个数字，在1~100之间：")
	fmt.Println("Can you guest it?")
	// fmt.Println(target)

	reader := bufio.NewReader(os.Stdin)
	success := false
	for i := 0; i < 10; i++ {
		fmt.Println("YOu have:", 10-i, "guest left.")
		fmt.Print("Make a guest:")
		input, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}
		input = strings.TrimSpace(input)
		guess, err := strconv.Atoi(input)
		if err != nil {
			log.Fatal(err)
		}

		if guess < target {
			fmt.Println("Oops, YOu guess is LOW.")
		} else if guess > target {
			fmt.Println("Oops, YOu guess is HIGH.")
		} else {
			success = true
			fmt.Println("Congratulations, guess, the game is over.")
			break
		}

	}
	if !success {
		fmt.Printf("Sorry for your number of times, His value is: %d the game is over !!\n", target)
	}

}
